<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<script src="validator.js" type="text/javascript"></script>

<script type="text/javascript">
<!--

window.onload = function(){
	// Add the elements to the validator
	var validator = new jsValidator();
	validator.elmts = {
		// This 'name' correspondent the field which has the name id.
		name: {
			// You can set multiple validators
			validators: {
				'IsString': {}, // No message set, the default msg of this field will be used
				'NoHTML': {
					// You can set for each validator an other message
					msg: 'HTML is not allowed!'
				},
			},
			
			// If there's isn't a validator wich fits to your needs, you can set a regex
			regex: /^option_[0-9]+.*$/,
			
			// The default message
			msg: 'This field must be a string'
		},
		test: {
			validator: 'IsString',
			// If one regex is not enough, you can set more in an Array
			regex: [{
					regex: /^start-.*$/,
					msg: 'This field must start with start-'
				},{
					regex: /^.*\-end/, // It must end with .com
					msg: 'This field must end with -end'
				}],
			msg: 'This field must be a valid string'
		},
		
		// This is an example of some simple validation, just the validation method and some message
		email: {
			validator: 'IsEmail',
			msg: 'This field must be a valid email adres'
		},
		text: {
			// You can create your own validate function too. You have to return true or false
			validator: function(value){
				// The length must be greather than 10 characters
				return value.length > 10;
			},
			msg: 'This textarea must be longer than 10 characters'
		},
		select: {
			regex: /^option_[0-9]+$/,
			msg: 'This value must begin with option_ and end with a number'
		}
	}
	// Fire the validator
	validator.init();

	// You can also make more forms with the validator
	var validator2 = new jsValidator();
	validator2.elmts = {
		name2: {
			validator: 'IsString',
			msg: 'This field must be a valid string'
		},
		age2: {
			validator: 'IsDigit',
			msg: 'This field must be a digit'
		}	}
	// Fire the validator
	validator2.init();

}


// -->
</script>

<title>Insert title here</title>
</head>
<body>

<form action="#">
	<p>
		<label for="name">Name</label> 
		<input type="text" id="name" name="name_field" />
	</p>
	<p>
		<label for="age">Test</label> 
		<input type="text" id="test" name="test_field" />
	</p>
	<p>
		<label for="email">E-mail</label> 
		<input type="text" id="email" name="email_field" />
	</p>
	<p>
		<label for="text">Text</label> 
		<textarea id="text" name="description"></textarea>
	</p>
	<p>
		<label for="select">Selectfield</label> 
		<select id="select" name="select_fied">
			<option value="option_1">One</option>
			<option value="option_2">Two</option>
			<option value="option_3">Three</option>
			<option>four</option>
		</select>
	</p>
	<p class="submit">
		<input type="submit" value="Submit" />
	</p>
</form>

<hr />

<form action="#">
	<p>
		<label for="name">Name</label> 
		<input type="text" id="name2" name="name_field" />
	</p>
	<p>
		<label for="age">Age</label> 
		<input type="text" id="age2" name="age_field" />
	</p>
	<p class="submit">
		<input type="submit" value="Submit" />
	</p>
</form>

</body>
</html>